﻿namespace dPet.Domain.Events.Handlers
{
	using dPet.Domain.Models;
	using dPet.Domain.Repositories;
	using Hangerd.Event;

	public class InventoryLOReportedEventHandler : IDomainEventHandler<InventoryLOReportedEvent>
	{
		private readonly IInventoryLORecordRepository _inventoryLORecordRepository;

		public InventoryLOReportedEventHandler(IInventoryLORecordRepository inventoryLORecordRepository)
		{
			_inventoryLORecordRepository = inventoryLORecordRepository;
		}

		public void Handle(InventoryLOReportedEvent e)
		{
			var productInventory = e.Source as ProductInventory;

			//添加报损报溢记录
			var inventoryLORecord = new InventoryLORecord(
				productInventory,
				e.LOType,
				e.Quantity,
				e.Operator);

			_inventoryLORecordRepository.Add(inventoryLORecord, false);
		}
	}
}
